package com.yidu.t299.service.ljc.impl;
import com.yidu.t299.dao.ljc.GoodstockMapper;
import com.yidu.t299.domain.ljc.Goodstock;
import com.yidu.t299.service.ljc.GoodstockBiz;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;

/**
 * @author 刘建常
 * @version 1.0
 * @description
 * @date:2023/3/16 9:44
 */
@Service
@Transactional
public class GoodstockBizImpl implements GoodstockBiz {
    @Autowired
    private GoodstockMapper goodstockMapper;

    @Override
    public int deleteByPrimaryKey(Integer goodsStockId) {
        return goodstockMapper.deleteByPrimaryKey(goodsStockId);
    }

    @Override
    public int insert(Goodstock record) {
        return goodstockMapper.insert(record);
    }

    @Override
    public Goodstock selectByPrimaryKey(Integer goodsStockId) {
        return goodstockMapper.selectByPrimaryKey(goodsStockId);
    }

    @Override
    public List<Goodstock> selectByPage(int rows, int page, String condition) {
        return goodstockMapper.selectByPage(rows, page, condition);
    }

    @Override
    public int selectCount(String condition) {
        return goodstockMapper.selectCount(condition);
    }

    @Override
    public int updateByPrimaryKey(Goodstock record) {
        return goodstockMapper.updateByPrimaryKey(record);
    }

    @Override
    public String getCondition(Goodstock record) {
        // 定义条件字符串变量，初始值为空格字符串
        String condition = " ";
        // 如果校区对象为空，则直接返回空条件字符串
        if (record == null) {
            return condition;
        }
        // 如果校区编号不为空(如果是基本类型就直接判断!=0)
        if (record.getGoodsStockId() != null) {
            condition += " and goods_stock_id = " + record.getGoodsStockId();
        }
        // 如果校区名称不为空
        if (record.getInName() != null && record.getInName().trim().length() != 0) {
            condition += " and in_name like '%" + record.getInName() + "%'";
        }

        if (record.getInPrice() != null) {
            condition += " and in_price = " + record.getInPrice();
        }

        if (record.getInNumber() != null) {
            condition += " and in_number like '%" + record.getInNumber() + "%'";
        }

        // 返回条件字符串
        return condition;
    }
}
